#!/bin/bash

if [ ! $# -eq 1 ]; then
 echo "Not enough parameters."
 exit
fi

INC_STAT="${1}_build.stat"
INC_HDR="${1}_build.h"

if [ ! -e $INC_STAT ]; then
 echo "Current BUILD number status file '${INC_STAT}' does not exists! Abort."
 exit
fi

BUILDPREV="`cat ${INC_STAT}`"
BUILDNUMBER=$((${BUILDPREV}+1))
echo "Build number is $BUILDNUMBER"
echo $BUILDNUMBER >$INC_STAT

echo "#ifndef BUILD_NUMBER_${1}" >$INC_HDR
echo "#define BUILD_NUMBER_STR_${1} \"$BUILDNUMBER\""  >>$INC_HDR
echo "#define BUILD_NUMBER_${1} $BUILDNUMBER"  >>$INC_HDR
echo "#endif //BUILD_NUMBER_${1}" >>$INC_HDR
echo "" >>$INC_HDR

exit
